//
//  RBBrandVC.m
//  zhongzhenglu
//
//  Created by mac on 2022/12/15.
//

#import "RBBrandVC.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import "RBSearchTagView.h"
#import "RBThemeConfig.h"
#import <Masonry.h>
#import "RBNavigationBar.h"
#import "RBTextField.h"
#import "UIButton+RBAdd.h"
#import <UIColor+YYAdd.h>
#import "UIViewController+RBAdd.h"
#import "RBPager.h"
#import "RanTool.h"
#import <UINavigationController+FDFullscreenPopGesture.h>
#import "UIButton+RBAdd.h"
#import "RBBrandSubVC.h"
#import "RBBrandClassResponse.h"

@interface RBBrandVC ()

@property(nonatomic, strong)RBPagerView *pagerView;
@property(nonatomic, strong)NSMutableDictionary *vcsDicM;
@property(nonatomic, strong)RBNavigationBar *navigationBar;
@property(nonatomic, strong) UILabel *titleL;

@property(nonatomic, strong) RBBrandClassResponse *response;

@end

@implementation RBBrandVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
    [self getData];
}

#pragma mark - Private

- (void)setup
{
    self.fd_prefersNavigationBarHidden = YES;
    self.view.backgroundColor = [UIColor colorWithHexString:@"#BDE3F8"];
    self.navigationBar.hidden = NO;

}

- (RBBrandSubVC *)vcWithIndex: (NSInteger)index
{
    RBBrandSubVC *vc = self.vcsDicM[@(index)];
    if (!vc)
    {
        vc = RBBrandSubVC.new;
        RBBrandClassModel *model = self.response.data[index];
        vc.id = model.id;
        [self addChildViewController:vc];
        self.vcsDicM[@(index)] = vc;
    }
    return vc;
}

- (void)fillData
{
    
}

#pragma mark - Network

- (void)getData
{
    __weak typeof(self) weak_self = self;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        
    } path:@"han_brand_cate" post:YES log:YES responseClass:RBBrandClassResponse.class desView:self.view showHud:YES showPlaceHolder:NO sucBlock:^(id data) {
        weak_self.response = data;
        weak_self.pagerView.hidden = NO;
        [weak_self.view bringSubviewToFront:weak_self.navigationBar];
    } failBlock:^(RBBrandClassResponse *data) {
        [weak_self.view showTip:data.message completion:nil];
    } reloadBlock:nil];
}

#pragma mark - Event

#pragma mark - Setter

#pragma mark - Getter

- (RBPagerView *)pagerView
{
    if (!_pagerView)
    {
        self.pagerView = ({
            RBPagerView *view = RBPagerView.new;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.edges.mas_equalTo(0);
            }];
            __weak typeof(self) weakSelf = self;
            view.getVcBlock = ^UIViewController * _Nonnull(NSInteger index) {
                return [weakSelf vcWithIndex:index];
            };
            CGFloat stickTop = kRBStatusBarHeight + kRBNavigationBarHeight;
            CGFloat imgH = Zoom(312);
            CGFloat headerH = Zoom(47);
            [view configWithHeaderStickTop:stickTop headerBottom:0 headerHeight:headerH floatViewHeight:imgH +headerH];
            [view setupWithModel:({
                RBPagerHeaderModel *model = RBPagerHeaderModel.new;
                model.titles = ({
                    NSMutableArray *arrayM = NSMutableArray.array;
                    for (RBBrandClassModel *model in self.response.data)
                    {
                        [arrayM addObject:model.class_name];
                    }
                    arrayM;
                });
                model.headerAttributeTitlesForNormalState = ({
                    NSMutableArray *arrayM = NSMutableArray.array;
                    for (NSString *title in model.titles)
                    {
                        [arrayM addObject:[RanTool attributeStringMaker:^(NSMutableArray *maker) {
                            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[RBThemeConfig textBlackColor] string:title];
                        }]];
                    }
                    arrayM;
                });
                model.headerAttributeTitlesForSelectedState = ({
                    NSMutableArray *arrayM = NSMutableArray.array;
                    for (NSString *title in model.titles)
                    {
                        [arrayM addObject:[RanTool attributeStringMaker:^(NSMutableArray *maker) {
                            [maker addAttributeStringWithImage:[UIImage imageNamed:@"brand3"] imageSize:CGSizeMake(Zoom(8), Zoom(14)) maxFont:[UIFont systemFontOfSize:Zoom(13)]];
                            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[RBThemeConfig textBlackColor] string:[@" " stringByAppendingString:title]];
                        }]];
                    }
                    arrayM;
                });
                model.backgroundColor = UIColor.clearColor;
                model.showSeperator = NO;
                model.showBottomLine = NO;
                model.buttonWidthStyle = RBPagerButtonWidthTitleWidthPlusPadding;
                model.headerButtonPadding = Zoom(19);
                model;
            })];
            view.yProgressBlock = ^(CGFloat yProgress) {
//                weakSelf.titleL.textColor = yProgress > 0.5? [RBThemeConfig textBlackColor]: UIColor.whiteColor;
//                [[weakSelf.navigationBar.naviBar getBackBtn] rbSetImage:[UIImage imageNamed:yProgress > 0.5? @"backBlack": @"backArror"]];
                weakSelf.navigationBar.backgroundAlpha = yProgress;
            };
            
            [view.pagerHeaderView.bottomLineView rbSetCornerRadius:Zoom(1.5)];
            
            view.floatView.backgroundColor = self.view.backgroundColor;
            view.backgroundColor = self.view.backgroundColor;
            
            UIView *topView = [RanTool imgViewWithMode:0 radius:0 imgName:@"brand2"];
            [view.floatView addSubview:topView];
            [topView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.top.mas_equalTo(0);
                make.height.mas_equalTo(imgH);
            }];
            
            view;
        });
    }
    return _pagerView;
}

- (RBNavigationBar *)navigationBar
{
    if (!_navigationBar)
    {
        self.navigationBar = ({
            RBNavigationBar *view = RBNavigationBar.new;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.mas_equalTo(0);
                make.height.mas_equalTo(kRBStatusBarHeight + kRBNavigationBarHeight);
            }];
            
            view.needGradientView = NO;
            view.backgroundAlpha = 0;
            view.bgColor = self.view.backgroundColor;
            
            UILabel *titleL = [RanTool labelWithFontSize:18 weight:0 color:[RBThemeConfig textBlackColor] align:0 text:@"品牌馆"];
            self.titleL = titleL;
            [view.naviBar addSubview:titleL];
            [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.mas_equalTo(0);
            }];

            [view.naviBar addBackBtnWithWidth:70 image:[UIImage imageNamed:@"backBlack"]];
            
            
            view;
        });
    }
    return _navigationBar;
}

- (NSMutableDictionary *)vcsDicM
{
    if (!_vcsDicM)
    {
        self.vcsDicM = NSMutableDictionary.dictionary;
    }
    return _vcsDicM;
}


@end
